package com.code.user.client.hystrix;

import com.code.AZPlan.model.bo.UserVipBO;
import com.code.commons.model.Model;
import com.code.commons.model.qo.PageQO;
import com.code.commons.model.vo.PageVO;
import com.code.user.client.UserClient;
import com.code.user.model.bo.*;
import com.code.user.model.po.*;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 用户的熔断回调类
 *
 * @author tangyifei
 */
@Component
@Slf4j
public class UserClientHystrix implements UserClient {

    @Override
    public User getUserCredential(@PathVariable("userId") String userId) {
        log.info("根据用户主键获取用户的凭证信息发生请求超时，走熔断！");
        return User.builder().build();
    }

    @Override
    public Boolean judgeUserPhoneIsExist(@PathVariable("userPhone") String userPhone) {
        log.info("判断用户手机号是否存在发生请求超时，走熔断！");
        return false;
    }

    @Override
    public Boolean judgeUserEmailIsExist(@PathVariable("userEmail") String userEmail) {
        log.info("判断用户邮箱是否存在发生请求超时，走熔断！");
        return false;
    }

    @Override
    public User registerUser(@RequestBody RegisterUser registerUser) {
        log.info("注册用户发生请求超时，走熔断！");
        return User.builder().build();
    }

    @Override
    public LoginUserCredential getUserByPhone(@PathVariable("userPhone") String userPhone) {
        log.info("通过手机号查询用户凭证信息发生请求超时，走熔断！");
        return LoginUserCredential.builder().build();
    }

    @Override
    public void resetPwd(@RequestParam("userId") String userId, @RequestParam("newPwd") String newPwd) {
        log.info("重置密码发生请求超时，走熔断！");
    }

    @Override
    public int addCoinBalance(@RequestBody UserCoinBalance userCoinBalance) throws Exception {
        log.info("增加用户钱包余额信息发生请求超时，走熔断！");
        return 0;
    }

    @Override
    public void updateUserCoinAddress(@RequestBody UserCoinBalance userCoinBalance) throws Exception {
        log.info("更新用户钱包相关币种地址信息发生请求超时，走熔断！");
    }

    @Override
    public List<UserAZPlanChannel> getAZPlanChannelList(@PathVariable("userId") String userId, @RequestParam("coinType") String coinType) {
        log.info("根据用户主键和币种类型获取入金通道列表发生请求超时，走熔断！");
        return Collections.emptyList();
    }

    @Override
    public int recharge(@RequestBody RechargeTranRecord rechargeTranRecord) {
        log.info("充值发生请求超时，走熔断！");
        return 0;
    }

    @Override
    public UserCoinBalance getUserCoinBalance(@RequestParam("userId") String userId, @RequestParam("coinType") String coinType, @RequestParam(value = "coinAddress", required = false) String coinAddress) {
        log.info("根据用户主键、币种类型、币种地址获取用户钱包信息发生请求超时，走熔断！");
        return UserCoinBalance.builder().build();
    }

    @Override
    public String getUserCoinAddressByUserId(@RequestParam("userId") String userId, @RequestParam("coinType") String coinType) {
        log.info("根据用户主键和币种类型获取用户钱包币种地址发生请求超时，走熔断！");
        return "getUserCoinAddressByUserId request timeout!";
    }

    @Override
    public BigDecimal getTotalRechargeAmount(@RequestParam("userId") String userId, @RequestParam("coinType") String coinType, @RequestParam("coinAddress") String coinAddress) {
        log.info("根据用户主键、币种类型、币种地址获取总的充值金额发生请求超时，走熔断！");
        return BigDecimal.ZERO;
    }

    @Override
    public UserCoinBalanceBO getUsdtVersion(@PathVariable("recommenderPhone") String recommenderPhone) {
        log.info("根据推荐人手机号获取USDT钱包版本号发生请求超时，走熔断！");
        return UserCoinBalanceBO.builder().build();
    }

    @Override
    public void bindingUserTokenAndUserPhone(@PathVariable("mobilePhone") String mobilePhone, @RequestParam("tokenId") String tokenId) {
        log.info("绑定用户手机号与用户登录token发生请求超时，走熔断！");
    }

    @Override
    public List<UserToken> getTokenList(@RequestBody List<UserVipBO> userVipBOS) {
        log.info("根据推荐人主键获取被推荐人的登录token列表发生请求超时，走熔断！");
        return Collections.emptyList();
    }

    @Override
    public List<UserCoinBalance> getUserWalletList(@RequestParam("coinType") String coinType) {
        log.info("根据币种类型获取相关用户钱包信息列表发生请求超时，走熔断！");
        return Collections.emptyList();
    }

    @Override
    public int reduceUserCoinBalance(@RequestBody UserCoinBalance userCoinBalance) {
        log.info("扣减用户钱包相关币种余额发生请求超时，走熔断！");
        return 0;
    }

    @Override
    public Map<String, Object> getDirectRecommends(@PathVariable("userId") String userId, @RequestParam(value = "entryMoneyState", required = false) Integer entryMoneyState, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        log.info("获取直推用户列表发生请求超时，走熔断！");
        return Maps.newHashMap();
    }

    @Override
    public String getUserTokenByUserPhone(@PathVariable("mobilePhone") String mobilePhone) {
        log.info("通过用户手机号获取用户登录token发生请求超时，走熔断！");
        return "get user token request timeout!";
    }

    @Override
    public int addUserCertification(@RequestBody UserCertification userCertification) {
        log.info("添加用户认证信息发生请求超时，走熔断！");
        return 0;
    }

    @Override
    public UserCertification getUserCertificationByUserId(@PathVariable("userId") String userId) {
        log.info("通过用户主键获取用户认证信息发生请求超时，走熔断！");
        return UserCertification.builder().build();
    }

    @Override
    public int getUserCertificationCountByCertificationNumber(@PathVariable("certificationNumber") String certificationNumber) {
        log.info("根据证件号码获取用户认证数发生请求超时，走熔断！");
        return 0;
    }

    @Override
    public UserCertificationBO getUserCertificationList(@RequestBody UserCertificationBO userCertificationBO) {
        log.info("根据用户认证业务对象中的参数查询用户认证信息发生请求超时，走熔断！");
        return UserCertificationBO.builder().build();
    }

    @Override
    public int updateUserCertification(@RequestBody UserCertification userCertification) {
        log.info("更新用户认证信息发生请求超时，走熔断！");
        return 0;
    }

    @Override
    public int updateSystemSetting(@RequestBody SystemSettingBO systemSettingBO) {
        log.info("更新系统设置信息发生请求超时，走熔断！");
        return 0;
    }

    @Override
    public SystemSettingBO getSystemSettingBySystemKey(@PathVariable("systemKey") String systemKey) {
        log.info("根据系统key获取系统设置信息发生请求超时，走熔断！");
        return SystemSettingBO.builder().build();
    }

    @Override
    public List<UserCoinBalance> getUserCoinBalanceList(@PathVariable("userId") String userId) {
        log.info("根据用户主键获取用户钱包列表发生请求超时，走熔断！");
        return Collections.emptyList();
    }

    @Override
    public PhoneBO getUserPhones(@RequestParam(value = "phone", required = false) String phone, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        log.info("根据用户手机号分页模糊获取用户手机号列表发生请求超时，走熔断！");
        return PhoneBO.builder().build();
    }

    @Override
    public int setUserOperate(@RequestBody UserOperateAuth userOperateAuth) {
        log.info("禁止或者取消用户的相关的操作发生请求超时，走熔断！");
        return 0;
    }

    @Override
    public UserOperateAuth getUserOperateAuthByUserIdAndOperateCode(@RequestParam String userId, @RequestParam String operateCode) {
        log.info("根据用户主键和操作码查询用户的操作权限发生请求超时，走熔断！");
        return UserOperateAuth.builder().build();
    }

    @Override
    public User add(@RequestBody User user) {
        log.info("添加用户信息发生请求超时，走熔断！");
        return User.builder().build();
    }

    @Override
    public int deleteById(@PathVariable("id") String id) {
        log.info("根据用户主键删除用户发生请求超时，走熔断！");
        return 0;
    }

    @Override
    public User updateByIdSelective(@PathVariable("id") String id, @RequestBody User record) {
        log.info("部分修改用户信息发生请求超时，走熔断！");
        return User.builder().build();
    }

    @Override
    public User updateById(@PathVariable("id") String id, @RequestBody User record) {
        log.info("全部修改用户信息发生请求超时，走熔断！");
        return User.builder().build();
    }

    @Override
    public User getById(@PathVariable("id") String id) {
        log.info("根据用户主键获取用户信息发生请求超时，走熔断！");
        return User.builder().build();
    }

    @Override
    public List<User> getByIds(@RequestBody Set<String> ids) {
        log.info("根据多个用户主键获取多个用户信息发生请求超时，走熔断！");
        return Collections.emptyList();
    }

    @Override
    public PageVO<User> getPage(@RequestBody PageQO<? extends Model> pageQO) {
        log.info("分页获取用户信息发生请求超时，走熔断！");
        return new PageVO<>();
    }

    @Override
    public String trace(@PathVariable("command") String cmd) {
        log.info("测试或诊断登录凭证信息发生请求超时，走熔断！");
        return "trace request timeout!";
    }
}
